<%@ page import="com.google.gson.Gson" %><%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2021/4/20
  Time: 20:42
  To change this template use File | Settings | File Templates.
--%>

<%@ page import="com.google.gson.Gson" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<script src="jsgol/jQuery.js"></script>

<head>
    <title>奖惩管理</title>
</head>

<body>
<%
    if (session.getAttribute("msg") != null) {
        out.print("<script> alert('" + session.getAttribute("msg") + "'); </script>");
        session.removeAttribute("msg");
    }
%>
<%@include file="Canvas.jsp" %>
<div style="width:800px;height: 700px;border: gray solid 1px;margin:0 auto;background: beige;margin-top: 7%;">
    <%@include file="header.jsp" %>
    <div class="botton" style="width:100%;height:430px;border: red solid 1px;margin: 0px auto;position: relative;">
        <table id="tableData" border="1" style="width: 100%;text-align: center">

        </table>
        <div style="position: absolute;top: 430px;">
            <img src="idemge/down.jpg" alt="">
        </div>
        <div style="float: right;font-weight: bold">

            <%
                // 用户总数，用于判断分多少页
                Long userLen = (Long) session.getAttribute("userLen");
                if (userLen != null) {
                    for (int i = 0; i < userLen / 10 + 1; i++) {
                        out.print("<a href='" + request.getContextPath() + "/rewlist?page=" + (i + 1) + "'>" + (i + 1) + "</a>");
                    }
                    out.print("共" + (userLen / 10 + 1) + "页");
                }
            %>
        </div>
        <a href="<%=request.getContextPath() %>/AddRewland.jsp" style="position: absolute;bottom: 40px;right: 15px;">添加奖惩信息</a>

    </div>
</div>

</body>
<script type="text/javascript" src="jsgol/protect.js"></script>
<script>
    var rewland = JSON.parse('<%=new Gson().toJson(session.getAttribute("rewlist")) %>')

    console.log(rewland);

    function createTable() {
        var data = $('#tableData');
        data.html(`<tr><th>编号</th><th>奖惩主题</th><th>奖励类型</th><th>奖励金额</th><th>奖励时间</th><th>操作<th></tr>`)
        for (let i = 0; i < rewland.length; i++) {
            data.append(`<tr>
            <td>${rewland[i].P_id?rewland[i].P_id:'无'}</td>
            <td>${rewland[i].P_theme?rewland[i].P_theme:'无'}</td>
            <td>${rewland[i].P_type?rewland[i].P_type:'无'}</td>
            <td>${rewland[i].P_money?rewland[i].P_money:'无'}</td>
            <td>${rewland[i].P_time?rewland[i].P_time:'无'}</td>
            <td><button onclick="">查看详情</button>
            <button onclick="dele(${i})">删除</button></td>
            </tr>`);

        }
    }

    function dele(index) {
        var i = confirm("确定要删除吗?");
        if (i == true) {
            location.href = 'rewdele?dele=' + rewland[index].P_id;
        }
    }

    createTable();
    $('#navMore').html('>奖惩查询');


</script>

<style>

    .botton {
        background: url(idemge/6.png) no-repeat;
        background-size: 100% 100%;
    }
</style>
</html>
